<?php
/**
* Letterman Newsletter Component
* 
* @package Letterman
* @author Soeren
* @copyright Soeren Eberhardt <soeren@virtuemart.net>
*   (who just needed an easy and *working* Newsletter component for Mambo 4.5.1 and mixed up Newsletter and YaNC)
* @copyright Mark Lindeman <mark@pictura-dp.nl> 
*    (parts of the Newsletter component by Mark Lindeman; Pictura Database Publishing bv, Heiloo the Netherland)
* @copyright Adam van Dongen <adam@tim-online.nl>
*    (parts of the YaNC component by Adam van Dongen, www.tim-online.nl)
*    
* @copyright Philip Sylvain <contact@sphilip.com>
*  	(MVC refactorization and AJAX)
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*
*/


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');

class LettermanViewSubscribers extends JView

{
	var $pagination = null ;
	
	function display( $tpl = null )
	{
		switch ($tpl) {
			case 'form':
				$this->editItem();
				break;
			default :
				$this->listIems();
				
		}
		
		parent::display($tpl);
	}
	
	
	function listIems()
	{
		
		$model = $this->get('items');
		jimport( 'joomla.html.pagination' );
		$this->pagination = new JPagination($model['total'], $model['limitstart'], $model['limit']);
		$this->assign( $model );
		
		$style = '<style type="text/css">' . PHP_EOL
    	       . '.icon-32-validate{background-image: url(../components/com_letterman/images/validate_f2.gif)}'
    	       .  PHP_EOL .'</style>';
		
		$mainframe =& JFactory::getApplication();
		$mainframe->addCustomHeadTag($style);
		
		JToolBarHelper::title( JText::_( 'Subscriber Manager' ), 'generic.png' );
    	JToolBarHelper::addNew();
    	JToolBarHelper::editList();
    	JToolBarHelper::custom('validate', 'validate', '', 'validate' );
    	JToolBarHelper::deleteList( JText::_( 'CONFIRM_DELETE_MSG' ) );
		
	}
	
	function editItem()
	{
		
		JRequest::setVar( 'hidemainmenu', 1 );
		
		$row =& $this->get('row');

		$title = $row->id ? JText::_( 'Edit subscriber' ) : JText::_( 'Add subscriber' );
		
		JToolBarHelper::title( $title , 'generic.png' );
		JToolBarHelper::save() ;
	    JToolBarHelper::apply() ;
	    JToolBarHelper::cancel() ;
	    
	    $this->assignRef('row' , $row );
	}
	
	function confirmed( &$row, $i )
	{
		$img 	= $row->confirmed ? 'tick.png' : 'publish_x.png' ;
		$task 	= $row->confirmed ? 'invalidate' : 'validate';
		$alt 	= $row->confirmed ? JText::_( 'Validate' ) : JText::_( 'Invalidate' );
		$action = $row->confirmed ? JText::_( 'Invalidate subscriber' ) : JText::_( 'Validate subscriber' );

		return '<a href="javascript:void(0);" onclick="return listItemTask(\'cb'. $i .'\',\''. $task .'\')" title="'
		       . $action .'"><img src="images/'. $img .'" border="0" alt="'. $alt .'" /></a>' ;
	}
	
	
}
